package com.infore.airsupervise.adapter;

import android.support.v4.content.ContextCompat;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.infore.airsupervise.R;
import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.app.StatusConst;
import com.infore.airsupervise.bean.AQIRealDataE;
import com.infore.airsupervise.bean.AirStationE;
import com.infore.airsupervise.utils.AirLevelUtil;

import java.util.List;

/**
 * 排名列表选择项适配器
 * Created by xiaotao on 2017/8/2.
 */

public class RankDataListAdapter extends BaseQuickAdapter<AQIRealDataE.RankBean, BaseViewHolder> {
    AirStationE.AirLevel airLevel =null;
    private int factorType ;


    public RankDataListAdapter(int layoutResId, List<AQIRealDataE.RankBean> data ,int factorType) {
        super(layoutResId, data);
        this.factorType = factorType;
    }

    public void setFactorType(int factorType){
        this.factorType = factorType;
    }
    @Override
    protected void convert(BaseViewHolder helper, AQIRealDataE.RankBean item) {
        if(factorType == StatusConst.AIR_TYPE_AQI){
            helper.setText(R.id.tv_station_value, "" + (int)item.getValue());
        }else {
            helper.setText(R.id.tv_station_value, "" + item.getValue());
        }
        helper.setText(R.id.tv_station_name, item.getStationName());
        ImageView indicator = helper.getView(R.id.view_indicator);
        airLevel = AirLevelUtil.getAirLevelObj(factorType, item.getValue(),item.isOnline());
        indicator.setImageResource(AirLevelUtil.getRealRankIcon(airLevel.getLevel()));
        helper.setText(R.id.tv_station_type , AirLevelUtil.getStationType(item.getStationType()));
        TextView staLevel = helper.getView(R.id.tv_station_level);
        if(factorType == StatusConst.AIR_TYPE_VOC){
            staLevel.setText("");
        }else {
            staLevel.setText(airLevel.getLevelStr());
        }
        staLevel.setTextColor(ContextCompat.getColor(mContext,airLevel.getColorRes()));
        helper.setTextColor(R.id.tv_station_value ,ContextCompat.getColor(mContext,airLevel.getColorRes()) );
    }
}
